package com.wx.mall.operate.controller;

import com.alibaba.fastjson.JSON;
import com.wx.mall.common.api.CommonResult;
import com.wx.mall.operate.dto.RebToDisDto;
import com.wx.mall.operate.entity.RebDiscount;
import com.wx.mall.operate.service.impl.RebDiscountServiceImpl;
import com.wx.mall.operate.vo.RebToDisVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author z
 * @since 2020-6-4
 */
@RestController
@RequestMapping("/reb/discount")
public class RebDiscountController {

    @Autowired
    RebDiscountServiceImpl rebDiscountService;

    @ApiOperation(value = "根据id查询一条")
    @GetMapping("/getFindRebDis")
    public CommonResult<List<RebToDisVo>> getFindRebToDisList(RebToDisDto dto){
        List<RebToDisVo> rebDisList = rebDiscountService.findRebDisList(dto);
        return CommonResult.success(rebDisList);
    }

    @ApiOperation(value = "修改满减")
    @PostMapping("/getDisFind")
    public CommonResult<RebDiscount> getFindDis(Long ids, String rebDiscount,String idList){
        List<RebDiscount> params= JSON.parseArray(rebDiscount,RebDiscount.class);
        List<RebDiscount> idLists = JSON.parseArray(idList,RebDiscount.class);
        int i = rebDiscountService.updateDiscount(ids,params,idLists);
        return i==1?CommonResult.success():CommonResult.failed();
    }

}
